class Lantern  extends egret.Sprite{
	private picUp:egret.Bitmap;
	private picDown:egret.Bitmap;

    private localXPast;
	private localYPast;
	private bl;
	private bl_LR;
	private num;
	private shape:egret.Shape;


	public constructor() {
        super();
        this.bl=false;
		this.bl_LR=true;
		this.num=1;

		this.shape=new egret.Shape();
		this.shape.graphics.beginFill(0x000000,0);
		this.shape.graphics.drawRect(0,0,740,1136);
		this.addChild(this.shape);

        this.picUp=new egret.Bitmap(RES.getRes("lantern2_png"));
        this.picUp.anchorOffsetX=this.picUp.width/2;
		this.picUp.anchorOffsetY=this.picUp.height/2;

		this.picDown=new egret.Bitmap(RES.getRes("lantern_down_png"));
		this.picDown.width=154/758*352;this.picDown.height=352;
        this.picDown.anchorOffsetX=this.picUp.width/2;
		this.picDown.anchorOffsetY=2;

		this.picDown.x=(this.picUp.width-this.picDown.width)/2;
		this.picDown.y=this.picUp.y+this.picUp.height/2-10;

        this.addChild(this.picDown);
        this.addChild(this.picUp);

		this.touchEnabled=true;

		this.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.TB,this);
		this.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.TM,this);	

	}
	private Weak(){

	}
	public Back(){
		var myThis=this;
		egret.Tween.get(this).wait(2300).to({y:1136/2-300},1000,egret.Ease.cubicOut);
		
		setTimeout(function(){
			myThis.bl_LR=true;
			myThis.bl=true;
			myThis.picUp.texture=RES.getRes("lantern2_png");				
			myThis.skewY=0;
			myThis.num=1;
		},1000);
	}

	private TB(evt:egret.TouchEvent){
		this.localXPast=evt.localX;
		this.localYPast=evt.localY;
	}
	private TM(evt:egret.TouchEvent){
		var myThis=this;
		if(this.bl_LR){
			if(this.localXPast-100>evt.localX){
				egret.Tween.get(this).to({skewY:this.skewY-180*this.num},1000,egret.Ease.backOut)
				this.bl_LR=false;
				this.bl=false;
				setTimeout(function(){myThis.bl_LR=true;myThis.bl=true},1000);

				this.num*=-1;
				if(this.num==-1){setTimeout(function(){myThis.picUp.texture=RES.getRes("lantern_png")},170);this.dispatchEvent(new LoadEvent("SlideLR",this.num));}
				if(this.num==1){setTimeout(function(){myThis.picUp.texture=RES.getRes("lantern2_png")},170);this.dispatchEvent(new LoadEvent("SlideLR",this.num));}
			}
		}
		if(this.bl){
			if(this.localYPast>evt.localY+60){
				egret.Tween.get(this).to({y:-800},1300,egret.Ease.cubicOut);
				this.bl=false;
			    this.bl_LR=false;				
				this.dispatchEvent(new LoadEvent("OpenTheDoor"));
			}
			else if(this.localYPast<evt.localY-60){
				egret.Tween.get(this).to({y:-800},800,egret.Ease.backIn);
				this.bl=false;
				this.bl_LR=false;	
				this.dispatchEvent(new LoadEvent("OpenTheDoor"));
			}
		}
	}
}